package com.xiaomaoguai.cloud.controller;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import com.xiaomaoguai.cloud.dao.UserRepository;
import com.xiaomaoguai.cloud.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

/**
 * @FileName: UserController.java
 * @Author :WeiHui.Zhang
 * @Data : 2016年11月11日 上午11:04:03
 * @Version:V1.00
 */
@RestController
public class UserController {

	@Autowired
	private UserRepository userRepository;

	@Autowired
	private EurekaClient discoveryClient;

	@GetMapping("/simple/{id}")
	public Optional<User> getUser(@PathVariable Long id) {
		return userRepository.findById(id);
	}

	@GetMapping("/eureka-instance")
	public InstanceInfo serviceUrl() {
		return discoveryClient.getNextServerFromEureka("microservice-provider-user", false);
	}
}
